
package com.snail.mobile.sim.oss.dictionaryinfo.service.impl;

import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;

import com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao;
import com.snail.mobile.sim.oss.dictionaryinfo.model.TblDictionaryInfoOss;
import com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager;
import com.sungrid.seine.oss.core.system.dao.SysLogDao;
import com.sungrid.seine.oss.framework.service.impl.BaseManagerImpl;
import com.sungrid.seine.oss.framework.util.StringHelper;

public class TblDictionaryInfoOssManagerImpl extends BaseManagerImpl implements TblDictionaryInfoOssManager 
{
    private TblDictionaryInfoOssDao dao;
    private SysLogDao sysLogDao;

    /**
     * Set the Dao for communication with the data layer.
     * @param dao
     */
    public void setTblDictionaryInfoOssDao(TblDictionaryInfoOssDao dao) 
    {
        this.dao = dao;
    }

    /**
     * Set the Log Dao for communication with the data layer.
     * 
     * @param dao
     */
    public void setSysLogDao(SysLogDao dao)
    {
        this.sysLogDao = dao;
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager#getTblDictionaryInfoOsss(com.snail.mobile.sim.oss.dictionaryinfo.model.TblDictionaryInfoOss)
     */
    public List getTblDictionaryInfoOsss(final TblDictionaryInfoOss tblDictionaryInfoOss) 
    {
        return dao.getTblDictionaryInfoOsss(tblDictionaryInfoOss);
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager#getTblDictionaryInfoOss(String nid)
     */
    public TblDictionaryInfoOss getTblDictionaryInfoOss(final String nid) 
    {
        return dao.getTblDictionaryInfoOss(new Integer(nid));
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager#saveTblDictionaryInfoOss(TblDictionaryInfoOss tblDictionaryInfoOss)
     */
    public void saveTblDictionaryInfoOss(TblDictionaryInfoOss tblDictionaryInfoOss) 
    {
        if (StringHelper.isNotNull(tblDictionaryInfoOss.getNid()))
        {
            dao.saveOrUpdateTblDictionaryInfoOss(tblDictionaryInfoOss);
        }
        else
        {
            dao.saveTblDictionaryInfoOss(tblDictionaryInfoOss);
        }
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager#removeTblDictionaryInfoOss(String nid)
     */
    public void removeTblDictionaryInfoOss(final String nid) 
    {
        dao.removeTblDictionaryInfoOss(new Integer(nid));
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssDao#removeTblDictionaryInfoOsss(Collection tblDictionaryInfoOsss)
     */
    public void removeTblDictionaryInfoOsss(final Collection tblDictionaryInfoOsss)
    {
        dao.removeTblDictionaryInfoOsss(tblDictionaryInfoOsss);
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssDao#saveTblDictionaryInfoOsss(Collection tblDictionaryInfoOsss)
     */
    public void saveTblDictionaryInfoOsss(final Collection tblDictionaryInfoOsss)
    {
        dao.saveTblDictionaryInfoOsss(tblDictionaryInfoOsss);
    }

	public List<TblDictionaryInfoOss> getDictionaryInfoOsslst(String dicName) {

	    DetachedCriteria criteria = DetachedCriteria.forClass(TblDictionaryInfoOss.class);

	    criteria.add(Expression.eq("sparamName", dicName).ignoreCase());

	    List list = this.dao.findList(criteria);
	    
	    return list;
	}

	public String getValueByKey(String name, String key) {
		    if(key==null){//修复没有结果时的空指针异常
		    	return "";
		    }
		    DetachedCriteria criteria = DetachedCriteria.forClass(TblDictionaryInfoOss.class);

		    criteria.add(Expression.eq("sparamName", name).ignoreCase());
		    criteria.add(Expression.eq("sparamKey", key).ignoreCase());

		    List list = this.dao.findList(criteria);
		    
		    return StringUtils.defaultString(((TblDictionaryInfoOss)list.get(0)).getSparamValue());
	}
    

    
   
}
